//
//  WriteAssistansView.swift
//  Chatup
//
//  Created by op on 2023/10/17.
//

import SwiftUI

struct WriteAssistansView: View {
    var tap:((MsgItem,Int) -> Void)?
    @StateObject var viewModel = WriteAssistansViewModel()
    var body: some View {
        GeometryReader { proxy in
            VStack(alignment: .leading){
                Text(String.i18nText("assistant_writing"))
                    .font(.system(size: 16,weight: .semibold))
                    .foregroundColor(.white)
                Spacer()
                    .frame(height: 14)
                ScrollView(.horizontal,showsIndicators: false) {
                    HStack {
                        ForEach(viewModel.items.indices, id: \.self) { index in
                            PressableEffectButton(action: {
                                tap?(.init(text: viewModel.items[index].des ?? ""), index)
                            }, label: {
                                VStack {
                                    Image(viewModel.items[index].iconName)
                                        .resizable()
                                        .frame(width: 34, height: 34)
                                        .padding(.top, 10)
                                    
                                    Text(viewModel.items[index].name)
                                        .font(.system(size: 14))
                                        .foregroundColor(.white.opacity(0.6))
                                        .padding(.bottom, 10)
                                        .lineLimit(2)
                                }
                                .padding()
                                .frame(width: (proxy.size.width - 60)/3, height: 102)
                                .background(.white.opacity(0.1))
                                .cornerRadius(12)
                                .overlay(
                                  RoundedRectangle(cornerRadius: 12)
                                    .inset(by: 0.5)
                                    .stroke(.white.opacity(0.1), lineWidth: 1)
                                )
                            
                            })
                        }
                    }
                }
                .frame(width: proxy.size.width)
            }
        }
    }
}


struct EntertainmentView:View {
    @StateObject var viewModel = WriteAssistansViewModel()
    var tap:((MsgItem,Int) -> Void)?

    var body: some View {
        VStack(alignment: .leading){
            Text(String.i18nText("intro1_entertainment"))
                .font(.system(size: 16,weight: .semibold))
                .foregroundColor(.white)
            Spacer()
                .frame(height: 14)
            HStack {
                ForEach(viewModel.entItems.indices, id: \.self) { index in
                    PressableEffectButton(action: {
                        tap?(.init(text: viewModel.entItems[index].des ?? ""), index)
                    }, label: {
                        ZStack(alignment: .leading) {
                            Rectangle()
                              .foregroundColor(.clear)
                              .frame(height: 90)
                              .background(.white.opacity(0.1))
                              .cornerRadius(12)
                              .overlay(
                                RoundedRectangle(cornerRadius: 12)
                                  .inset(by: 0.5)
                                  .stroke(.white.opacity(0.1), lineWidth: 1)
                              )
                            
                            HStack(alignment:.center) {
                                Text(viewModel.entItems[index].name)
                                    .font(.system(size: 14))
                                    .foregroundColor(.white)
                                Image(viewModel.entItems[index].iconName)
                                    .resizable()
                                    .frame(width: 60, height: 60)
                            }
                            .padding(.leading,15)
    //                        .padding(.vertical,15)
                        }
//                        .contentShape(Rectangle())
//                        .onTapGesture {
//                            tap?(.init(text: item.des ?? ""))
//                        }
                    })
                }
            }
        }
    }
}

struct QuickResponseView:View {
    @StateObject var viewModel = WriteAssistansViewModel()
    var tap:((MsgItem,Int) -> Void)?

    var body: some View {
        VStack(alignment: .leading){
            Text(String.i18nText("assistant_quick_response"))
                .font(.system(size: 16,weight: .semibold))
                .foregroundColor(.white)
            Spacer()
                .frame(height: 14)
            VStack {
                ForEach(viewModel.quickItems.indices, id: \.self) { index in
                    PressableEffectButton(action: {
                        tap?(.init(text: viewModel.quickItems[index].name), index)
                    }, label: {
                        ZStack(alignment: .leading) {
                            Rectangle()
                              .foregroundColor(.clear)
                              .frame(height: 53)
                              .background(.white.opacity(0.1))
                              .cornerRadius(12)
                              .overlay(
                                RoundedRectangle(cornerRadius: 12)
                                  .inset(by: 0.5)
                                  .stroke(.white.opacity(0.05), lineWidth: 1)
                              )
//                            RoundedRectangle(cornerRadius: 12)
//                                .frame(height: 53)
//                                .foregroundColor(.white.opacity(0.05))
//                            
//                            RoundedRectangle(cornerRadius: 12)
//                                .stroke(.white.opacity(0.1), lineWidth: 1)
//                                .frame(height: 53)
//                            RoundedRectangle(cornerRadius: 12)
//                                .frame(height: 53)
//                                .foregroundColor(.white.opacity(0.15))
                            HStack {
                                Spacer()
                                    .frame(width: 16)
                                Text(viewModel.quickItems[index].name)
                                    .font(.system(size: 14))
                                    .foregroundColor(.white.opacity(0.6))
                                    .multilineTextAlignment(.leading)
                            }
    //                        .padding()
                        }
//                        .contentShape(Rectangle())
//                        .onTapGesture {
//                            tap?(.init(text: item.name))
//                        }
                    })
                }
            }
        }
    }
}

#Preview {
    QuickResponseView()
}
